export enum NetType {
    GET = 'GET',
    POST = 'POST',
    PUT = 'PUT',
    DELETE = 'DELETE',
}

export enum ContentTypeEnum {
    // json
    JSON = 'application/json;charset=UTF-8',
    // form-data qs
    FORM_URLENCODED = 'application/x-www-form-urlencoded;charset=UTF-8',
    // form-data  upload
    FORM_DATA = 'multipart/form-data;charset=UTF-8'
}

export interface IApiData {
    netType: NetType,
    api: String,
    param: any | null,
    contentTypo: ContentTypeEnum | undefined;
}
export class ApiDataGet implements IApiData {
    netType: NetType = NetType.GET;
    api: String;
    param: any;
    contentTypo: ContentTypeEnum | undefined;
    constructor(api: String, param: any) {
        this.api = api
        this.param = param
    }
}
import axios from 'axios';
import type { AxiosRequestConfig, AxiosInstance, AxiosResponse, AxiosError } from 'axios';
import { type } from 'os';
import { config } from 'process';
import { handleError } from 'vue';
class Data1 {
    name: string | undefined
}
interface Data2 extends Data1 {
    (id: string): string
}

// const test2= Data2("123"){
//     name:"1"
// }
const mAxiosInstance: AxiosInstance = axios.create({
    timeout: 10000
});

type APISchema = Record<string, {
    request: Record<string, any> | void;
    response: Record<string, any> | any;
}>;
interface HccAPISchema extends APISchema {


    // getUser2(){

    // }
    getUser: {
        request: {

        };
        response: {

        }
    }
}

export type ApiConfig = {
    netType: NetType
    api: string
    contentType?: ContentTypeEnum
}
export type YcNetData = Record<string, {
    request: Record<string, any> | void;
    response: Record<string, any> | any;
}>;

export type YcApiT<T extends YcNetData> = {
    [Keys in keyof T]: ApiConfig

}
export interface NetDataHcc extends YcNetData  {
    login: {
        request: {
            userName: string,
            userPassword: string
        }
        response: {
            token: string
        }
    }
    getUserInfo: {
        request: {

        }
        response:(data:{userId?:string,userType?:string})=>{
            // return Promise.resolve()
        }
    }
}

export class NetConfigHcc implements YcApiT<NetDataHcc>  {
    [x: string]: ApiConfig;
    // [requestName: string]: ApiConfig;
    login: ApiConfig = {
        netType: NetType.POST,
        api: "/hcc/user/${id}",
        contentType: ContentTypeEnum.FORM_DATA,
    }
    getUserInfo = {
        netType: NetType.GET,
        api: "/hcc/getUserInfo",
    }
}
/*  注解式未知，方法<T extends ApiConfig>未知 */
export interface Test3 {
    login: <T extends ApiConfig>(params: string) => void
}
function test3() {
    type Tst = Record<string, string>
}
type LoginJson = { name: string }


export class YcAxios {
    private static mInstance = new YcAxios()
    private mAxiosInstance: AxiosInstance
    private constructor() {
        this.mAxiosInstance = axios.create({
            baseURL: "",
            withCredentials: false,
            headers: {},
        });
        this.mAxiosInstance.interceptors.request.use((config: AxiosRequestConfig) => {
            // return ""
            return config
        })
        this.mAxiosInstance.get<LoginJson>("").then(res => {
            res.data.name
        })
    }
    public static getInstance() {
        return YcAxios.mInstance;
    }

    // public static getApiService<T extends YcNetData, R extends YcApiT<T>>(apis: R): T {
    //     let apiService: YcNetData = Object.create(null);
    //     const axios = this.getInstance()
    //     for (const apiName in apis) {
    //         const apiConfig = apis[apiName];
    //         apiService[apiName] = 
    //     }
    //     return apiService
    // }
    // test() {
    //     YcAxios.mAxiosInstance.interceptors.request.use((axiosRequestConfig) => {
    //         axiosRequestConfig.baseURL
    //         const headerHandlers = ()

    //     })
    // }
}
function test() {
    // const apiService = YcAxios.getApiService<NetDataHcc, NetConfigHcc>(new NetConfigHcc())
    // apiService.login("张三", "1234").token
}
/**
 * 1.开始
 * 2.成功
 * 3.失败
 * 4.是否显示加载框
 * 5.多个并发
 * 6.多个同步
 * 7.区分模块
 * 8.重新请求
 * 9.时间戳缓存问题
 */